package com.googlecode.lohr.tools.compiler;

import java.io.File;
import java.util.HashMap;
import java.util.Stack;

import com.googlecode.lingwah.grammars.ALFGrammar;
import com.googlecode.lohr.parser.combinators.annotations.ElementType;
import com.googlecode.lohr.parser.combinators.node.MatchResult;
import com.googlecode.lohr.parser.combinators.node.MatchNavigation;
import com.googlecode.lohr.parser.combinators.node.MatchVistor;

public class LohrRDFCreator implements MatchVistor {
	
	// value keys
	private static final String NODE= "node";
	private static final String SUBJECT= "subject"; // current subject uri
	
	private File _destFile;
	private String _baseURI;
	private Stack<HashMap<String, Object>> _valueStack= new Stack<HashMap<String,Object>>();
	
	

	public LohrRDFCreator(File destFile) {
		_destFile= destFile;
	}
	
	

	@Override
	public boolean visit(MatchResult node) {
		HashMap<String, Object> prev= _valueStack.lastElement();
		HashMap<String, Object> values= new HashMap<String, Object>(prev);
		values.put(NODE, node);
		_valueStack.push(values);
		return true;
	}
	@Override
	public void leave(MatchResult node) {
		_valueStack.pop();
	}

	@ElementType(ALFGrammar.OBJECT_DEFINITION)
	public boolean visitObjectDefinition(MatchResult node) {
		// TODO Auto-generated method stub
		return true;
	}

	@ElementType(ALFGrammar.OBJECT_REFINEMENT)
	public boolean visitObjectRefinement(MatchResult node) {
		// TODO Auto-generated method stub
		return true;
	}
	
	@ElementType(ALFGrammar.PREDICATE_STATEMENT)
	public boolean visitPredicateStatement(MatchResult node) {
		process(node);
		String subjectURI= getSubjectURI();
		String id= MatchNavigation.findById(node, ALFGrammar.IDENTIFIER).getText();
		// TODO Auto-generated method stub
		return true;
	}



	private String getSubjectURI() {
		return (String)_valueStack.lastElement().get(SUBJECT);
	}

}
